package com.sh.suhe.utildemos.views.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sh.suhe.utildemos.R;
import com.sh.suhe.utildemos.SDKManager;
import com.sh.suhe.utildemos.model.PDAData;
import com.sh.suhe.utildemos.utils.JsonUtil;
import com.sh.suhe.utildemos.utils.LogUtil;
import com.sh.suhe.utildemos.utils.socket.DataEngine;
import com.sh.suhe.utildemos.utils.socket.DataSourceProxy;
import com.sh.suhe.utildemos.utils.socket.util.EntityObject;

public class SocketScanActivity extends AppCompatActivity {
    TextView re_tv;
    LinearLayout tipLay,tipWlLay,tipGwLay;
    PDAData param  = new PDAData();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_socket_scan);
        re_tv = findViewById(R.id.re_tv);
        tipLay = findViewById(R.id.tip_lay);
        tipWlLay = findViewById(R.id.wl_lay);
        tipGwLay = findViewById(R.id.gw_lay);

        SDKManager.getInstance().setContext(this);
        //初始化socket
        DataEngine.getInstance().init();
    }
    public void sendData(){
//        re_tv.text="请求中。。。";
        DataEngine.getInstance().request(EntityObject.SEND_SCAN,param, new DataSourceProxy.IRequestCallback(){
            @Override
            public void callback(boolean success, EntityObject data) {

                if (success){
                    PDAData str = (PDAData) data.getEntity();
                    re_tv.setText(JsonUtil.object2Json(str));
                }else{
                    re_tv.setText(JsonUtil.object2Json("请求失败"));
                }
                    LogUtil.d("SocketActivity","data is show");
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        DataEngine.getInstance().release();

    }

    public void doClick(View view) {
        tipLay.setVisibility(View.GONE);
        tipWlLay.setVisibility(View.GONE);
        tipGwLay.setVisibility(View.GONE);
        switch (view.getId()){
            case R.id.scan_wl_but:
                tipWlLay.setVisibility(View.VISIBLE);
                param.setId("111111我都呃呃呃");
                break;
            case R.id.scan_gw_but:
                tipGwLay.setVisibility(View.VISIBLE);
                param.setName("22222222");
                break;
            case R.id.sen_but:
                sendData();
                break;
        }
    }
}
